package com.chengyu.core.controller.shop;

import com.chengyu.core.controller.ShopBaseController;
import com.chengyu.core.domain.form.UmsShopOwnLevelForm;
import com.chengyu.core.entity.CommonResult;
import com.chengyu.core.exception.ServiceException;
import com.chengyu.core.model.UmsShopLevel;
import com.chengyu.core.model.UmsShopLevelPrice;
import com.chengyu.core.model.UmsShopOwnLevel;
import com.chengyu.core.service.shop.ShopLevelService;
import com.chengyu.core.service.shop.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @title  商家等级
 * @author LeGreen
 * @date   2022/5/9
 */
@Api(tags = "商家等级")
@Controller
@RequestMapping("/member")
public class ShopLevelController extends ShopBaseController {

	@Autowired
	private ShopLevelService shopLevelService;

	@ApiOperation(value = "店铺等级")
	@ResponseBody
	@RequestMapping(value="/shopLevel/list", method=RequestMethod.GET)
	public CommonResult<List<UmsShopLevel>> get(String type) throws ServiceException {
		List<UmsShopLevel> umsShopLevels = shopLevelService.listShopLevel(false,false,1,type);
		return CommonResult.success(umsShopLevels);
	}

	@ApiOperation(value = "根据等级ID查看等级价格信息")
	@ResponseBody
	@RequestMapping(value="/shopLevel/getShopLevelPriceByLevel", method=RequestMethod.GET)
	public CommonResult<List<UmsShopLevelPrice>> getShopLevelPriceByLevel(Integer levelId) throws ServiceException {
		List<UmsShopLevelPrice> umsShopLevelPrices = shopLevelService.getShopLevelPriceByLevelId(levelId,1);
		return CommonResult.success(umsShopLevelPrices);
	}


	@ApiOperation(value = "根据等级价格ID查看等级价格和等级信息")
	@ResponseBody
	@RequestMapping(value="/shopLevel/getShopLevelAndPriceByPriceLevel", method=RequestMethod.GET)
	public CommonResult<List<UmsShopOwnLevelForm>> getShopLevelAndPriceByPriceLevel() throws ServiceException {
		List<UmsShopOwnLevelForm> umsShopOwnLevelList = shopLevelService.getShopOwnLevelPriceById(getCurrentShopId());
		return CommonResult.success(umsShopOwnLevelList);
	}

    @ApiOperation(value = "根据等级价格ID查看等级价格和等级信息")
    @ResponseBody
    @RequestMapping(value = "/shopLevel/getShopLevelAndPriceByPriceLevel2", method = RequestMethod.GET)
    public CommonResult<Map> getShopLevelAndPriceByPriceLevel2() throws ServiceException {
        Integer level = getCurrentShop().getLevel();
        if (level != null) {
            Map shopLevelPriceById = shopLevelService.getShopLevelPriceById(level);
            return CommonResult.success(shopLevelPriceById);
        } else {
            return CommonResult.success(null);
        }
    }

	@ApiOperation(value = "判断是否为会员")
	@ResponseBody
	@RequestMapping(value = "/shopLevel/checkShopLevel", method = RequestMethod.GET)
	public CommonResult<Map> checkShopLevel() throws ServiceException {
		shopLevelService.checkShopLevel(getCurrentShopId());
		return CommonResult.success(null);
	}
}